package com.ytd.common.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.lang.reflect.Type;

/**
 * Gson 处理类
 *
 * @author gaoguanchao
 * @since 2023/3/29
 */
public class GsonUtil {
    private static Gson sGson = new GsonBuilder().disableHtmlEscaping().create();

    public static <T> T fromJson(String json, Class<T> classOfT) {
        return sGson.fromJson(json, classOfT);
    }

    public static <T> T fromJsonForObj(Object object, Class<T> classOfT) {
        return sGson.fromJson(sGson.toJson(object), classOfT);
    }

    public static <T> T fromJsonForObj(Object object, Type type) {
        return sGson.fromJson(sGson.toJson(object), type);
    }

    public static String toJson(Object data) {
        return sGson.toJson(data);
    }

    public static <T> T fromJson(String json, Type typeOfT) {
        return sGson.fromJson(json, typeOfT);
    }
}
